package com.example.webviewdemo;

import ohos.agp.components.webengine.BrowserAgent;
import ohos.agp.components.webengine.WebView;
import ohos.app.Context;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;
/**WebChromeClient
* 观测浏览事件
 * 通过setBrowserAgent方法设置自定义BrowserAgent对象，以观测JavaScript事件及通知等：
* */
public class ExampleBrowserAgent extends BrowserAgent {
    private static final HiLogLabel LABEL = new HiLogLabel(HiLog.LOG_APP, 0x00201, "MY_TAG");
    public ExampleBrowserAgent(Context context) {
        super(context);
    }

    @Override
    public void onTitleUpdated(WebView webview, String title) {
        super.onTitleUpdated(webview, title);
        // 标题变更时自定义处理
        HiLog.info(LABEL,"标题变更时自定义处理 title = "+title);
    }

    @Override
    public void onProgressUpdated(WebView webview, int newProgress) {
        super.onProgressUpdated(webview, newProgress);
        // 加载进度变更时自定义处理
        HiLog.info(LABEL,"加载进度变更 =" +newProgress);
    }
}
